from bin.ini import Ini


class SetUpAction:

    def __init__(self,sta,comboBox):
        self.sta = sta
        self.comboBox = comboBox

    def add(self,objName, url):
        """关联新增按钮"""
        ini = Ini()
        if ini.set('obj',objName,url):
            self.comboBox.addItem(objName)
            self.sta.showMessage('添加成功')

    def delete(self, obj):
        ini = Ini()
        if ini.get('default_obj','name') == obj:
            self.sta.showMessage('不可删除默认项目')
        else:
            if ini.deleteObj(obj):
                self.comboBox.clear()
                self.comboBox.addItems(ini.getObj())
                self.sta.showMessage('删除成功')

    def change(self, obj, url):
        ini = Ini()
        if ini.set('obj', obj, url):
            self.sta.showMessage('修改成功')


